﻿using System.Globalization;
using System.Xml.Linq;
using Microsoft.Xna.Framework;

namespace IcicleFramework.Components.Damage
{
    public class DamageComponent : BaseComponent, IDamageComponent
    {
        /// <summary>
        /// Gets or sets the damage caused by this DamageComponent.
        /// </summary>
        public float Damage { get; set; }

        public DamageComponent()
        {
        }

        public DamageComponent(int damage)
        {
            this.Damage = damage;
        }

        protected DamageComponent(DamageComponent old)
            : base (old)
        {
            this.Damage = old.Damage;
        }

        public override void Update(GameTime gameTime) { }

        public override IBaseComponent DeepClone()
        {
            return new DamageComponent(this);
        }

        public override void Deserialize(XElement element)
        {
            //All we want is the damage caused!
            if (element.Element("damage") != null)
            {
                this.Damage = float.Parse(element.Element("damage").Value, NumberStyles.Float,
                                          CultureInfo.InvariantCulture);
            }
        }
    }
}
